home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Viewers / VideoStreamV1.0 / Source / mpegDecodeSrc / gdith.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  3.6 KB  |  135 lines

  1. /*
  2.  * Copyright (c) 1992 The Regents of the University of California.
  3.  * All rights reserved.
  4.  * 
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose, without fee, and without written agreement is
  7.  * hereby granted, provided that the above copyright notice and the following
  8.  * two paragraphs appear in all copies of this software.
  9.  * 
  10.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  11.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  12.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  * 
  15.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20.  */
  21. #include <math.h>
  22. #include "video.h"
  23. #include "dither.h"
  24.  
  25. /* Array that remaps color numbers to actual pixel values used by X server. */
  26.  
  27. unsigned char pixel[256];
  28.  
  29. /* Arrays holding quantized value ranged for lum, cr, and cb. */
  30.  
  31. int lum_values[LUM_RANGE];
  32. int cr_values[CR_RANGE];
  33. int cb_values[CB_RANGE];
  34.  
  35.  
  36. /* Structures used by the X server. */
  37.  
  38. Display *display;
  39.  
  40. /*
  41.  *--------------------------------------------------------------
  42.  *
  43.  * ConvertColor --
  44.  *
  45.  *    Given a l, cr, cb tuple, converts it to r,g,b.
  46.  *
  47.  * Results:
  48.  *    r,g,b values returned in pointers passed as parameters.
  49.  *
  50.  * Side effects:
  51.  *      None.
  52.  *
  53.  *--------------------------------------------------------------
  54.  */
  55.  
  56. static void
  57. ConvertColor(l, cr, cb, r, g, b)
  58.      unsigned char l, cr, cb;
  59.      unsigned char *r, *g, *b;
  60. {
  61.   double fl, fcr, fcb, fr, fg, fb;
  62.  
  63.   fl = (double) l;
  64.   fcr =  ((double) cr) - 128.0;
  65.   fcb =  ((double) cb) - 128.0;
  66.  
  67.  
  68.   fr = fl + (1.40200 * fcb);
  69.   fg = fl - (0.71414 * fcb) - (0.34414 * fcr);
  70.   fb = fl + (1.77200 * fcr);
  71.  
  72.   if (fr < 0.0) fr = 0.0;
  73.   else if (fr > 255.0) fr = 255.0;
  74.  
  75.   if (fg < 0.0) fg = 0.0;
  76.   else if (fg > 255.0) fg = 255.0;
  77.  
  78.   if (fb < 0.0) fb = 0.0;
  79.   else if (fb > 255.0) fb = 255.0;
  80.  
  81.   *r = (unsigned char) fr;
  82.   *g = (unsigned char) fg;
  83.   *b = (unsigned char) fb;
  84.  
  85. }
  86.  
  87. /* Array back mapping pixel value to color number. Used for debugging and dumping
  88.    purposes. 
  89. */
  90.  
  91. static char backpixel[256];
  92.  
  93.  
  94.  
  95. /*
  96.  *--------------------------------------------------------------
  97.  *
  98.  * ExecuteDisplay --
  99.  *
  100.  *    Actually displays display plane in previously created window.
  101.  *
  102.  * Results:
  103.  *    None.
  104.  *
  105.  * Side effects:
  106.  *    None.
  107.  *
  108.  *--------------------------------------------------------------
  109.  */
  110.  
  111. /***************************************************************
  112.     vid_stream->current->display is a pointer to a bitmap of dimensions
  113.         vid_stream->mb_width * 16 by vid_stream->mb_height * 16.  The RGB 
  114.         data are pixel interleaved. - WAR
  115. ***************************************************************/
  116. extern int writeToStdout;
  117.  
  118. void ExecuteDisplay(vid_stream)
  119. VidStream *vid_stream;
  120. {
  121.     int iWidth, iHeight;
  122.  
  123.     ++totNumFrames;
  124.     fwrite((void *) &totNumFrames, (size_t) sizeof(int), (size_t) 1, stdout);
  125.     iWidth = (vid_stream->mb_width << 4);
  126.     fwrite((void *) &iWidth, (size_t) sizeof(int), (size_t) 1, stdout);
  127.     iHeight = (vid_stream->mb_height << 4);
  128.     fwrite((void *) &iHeight, (size_t) sizeof(int), (size_t) 1, stdout);
  129.     fwrite((void *) vid_stream->current->display, (size_t) sizeof(char), 
  130.             (size_t) (3*iWidth*iHeight), stdout);
  131.     return;
  132. }
  133.  
  134.  
  135.